package com.rs2hd.combat;

import com.rs2hd.model.NPC;
import com.rs2hd.model.Player;
import com.rs2hd.model.World;
import com.rs2hd.util.Misc;
import com.rs2hd.packetbuilder.StaticPacketBuilder;
import com.rs2hd.content.NPCDROP;
import com.rs2hd.util.ItemManager;
import com.rs2hd.model.Entity;

public class NpcCombat {

        private Entity entity;
        public Player p;
	private NPC n;
	private boolean attacking = false;
	private int enemyIndex = 0;
	private int combatDelay;
	public NpcCombat(NPC n) {
		this.n = n;
	}
	public void tick() {
		if (attacking) {
			attack();
		}
		if (combatDelay > 0) {
			combatDelay--;
		}
	}
	public void attack() {
		if (n == null)
			return;
		if (combatDelay > 0)
			return;
		if (n.isDead() || n.getHp() <= 0) {
			attacking  = false;
			return;
		}
		final Player opp = World.getInstance().getPlayerList().get(enemyIndex);
		if (opp == null)
			return;
		if (opp.isDead()) {
			attacking = false;
			return;
		}
		final int distance = Misc.getDistance(n.getLocation().getX(), n.getLocation().getY(),opp.getLocation().getX(), opp.getLocation().getY());
		if (distance <= 10) { 
			n.animate(n.getAttackAnimation());
			combatDelay = n.getAttackSpeed();
			if (opp.getEquipment().get(3) != null)
				opp.animate(opp.getEquipment().getDefenceAnimation());
			else 
				opp.animate(404);
			opp.hit(n.getMaxHit());
			n.turnTemporarilyTo(opp);
		}
	}
	public void setAttacking(boolean bool) {
		this.attacking = bool;
	}
	public void setCombatDelay(int i) {
		this.combatDelay = i;
	}
	public void setEnemy(int i) {
		this.enemyIndex = i;
	}
}
